﻿<UserControl x:Class="Locator.Silverlight.Client.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:map="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
             mc:Ignorable="d"
             Height="600"
             d:DesignWidth="1200"
             DataContext="{Binding Main, Source={StaticResource Locator}}" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">

    <UserControl.Resources>
        <!--<ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Skins/MainSkin.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>-->
        <DataTemplate x:Key="PushPinTemplate">
            <map:Pushpin map:Location="{Binding Location}" MouseLeftButtonUp="Pushpin_MouseLeftButtonUp">
                <TextBlock Foreground="Black" FontSize="10" TextAlignment="Center" Text="{Binding InventoryInfo.Count}"/>
                <ToolTipService.ToolTip>
                    <Border MinHeight="40" Margin="-10,-5,-10,-5"
MinWidth="150" Background="WhiteSmoke"
Opacity="1" VerticalAlignment="Top"
BorderBrush="Black" BorderThickness="1" CornerRadius="10" >
                        <StackPanel>
                            <TextBlock Text="{Binding Address}" />
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="Product" Margin="0" TextWrapping="Wrap" Width="350" />
                                <TextBlock Text="Amount" Margin="0" TextWrapping="Wrap" Width="50" />
                            </StackPanel>
                            <ItemsControl ItemsSource="{Binding InventoryInfo}">
                                <ItemsControl.Resources>
                                    <DataTemplate x:Key="ResultItemTemplate">
                                        <StackPanel Margin="1,0,1,0" Orientation="Horizontal">
                                            <TextBlock Text="{Binding Product.Name}" Margin="0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="350" />
                                            <TextBlock Text="{Binding NumberInStock}" Margin="0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="50" />
                                        </StackPanel>
                                    </DataTemplate>
                                </ItemsControl.Resources>
                                <ItemsControl.ItemTemplate>
                                    <StaticResource ResourceKey="ResultItemTemplate"/>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </StackPanel>
                    </Border>
                </ToolTipService.ToolTip>
            </map:Pushpin>
        </DataTemplate>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        <map:Map Name="mapDrinks" CopyrightVisibility="Collapsed" CredentialsProvider="{StaticResource MyCredentials}" Foreground="Black" Center="43.6,-79.5,0" ZoomLevel="10" Culture="en-CA" Mode="Road">
            <map:MapItemsControl x:Name="ListOfItems" ItemTemplate="{StaticResource PushPinTemplate}" ItemsSource="{Binding StoresWithInventories}"/>
            <map:MapLayer x:Name="Overlay"/>
        </map:Map>
        <ComboBox Height="23" Margin="196,40,0,0" Name="comboBoxProducts" VerticalAlignment="Top" ItemsSource="{Binding Products}" DisplayMemberPath="Name" SelectedItem="{Binding CurrentProduct, Mode=TwoWay}" HorizontalAlignment="Left" Width="120" />
        <ComboBox Height="23" HorizontalAlignment="Left" Margin="70,40,0,0" Name="comboBoxStores" VerticalAlignment="Top" Width="120" ItemsSource="{Binding Stores}" DisplayMemberPath="Address" SelectedItem="{Binding CurrentStore, Mode=TwoWay}"/>
        <Button Content="Find" Height="30" HorizontalAlignment="Left" Margin="322,36,0,0" Name="buttonFind" VerticalAlignment="Top" Width="75" Command="{Binding FindProductsCommand}" FontSize="16" FontWeight="Bold"  />
        <toolkit:Expander Header="Results" Width="462" HorizontalAlignment="Left" Margin="30,72,0,12" Opacity="0.8" FontSize="15" IsExpanded="True" Background="WhiteSmoke">
            <toolkit:Expander.HeaderTemplate>
                <DataTemplate>
                    <StackPanel Background="WhiteSmoke">
                        <TextBlock Text="Results"></TextBlock>
                    </StackPanel>
                </DataTemplate>
            </toolkit:Expander.HeaderTemplate>
            <ScrollViewer>
                <ItemsControl ItemsSource="{Binding StoresWithInventories}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Background="CornflowerBlue" MouseLeftButtonUp="StackPanel_MouseLeftButtonUp">
                                <TextBlock Text="{Binding Address}" FontSize="14" Foreground="Black" Width="450" TextWrapping="Wrap" />
                                <ItemsControl ItemsSource="{Binding InventoryInfo}">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal" Background="SkyBlue">
                                                <TextBlock Text="{Binding Product.Name}" Width="400" Foreground="Black" FontSize="11" />
                                                <TextBlock Text="{Binding NumberInStock}" Foreground="Black" Width="50" FontSize="11" />
                                            </StackPanel>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </StackPanel>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>
        </toolkit:Expander>
        <Button Content="Manage Products" Height="23" Margin="0,40,284,0" Name="buttonManageProducts" VerticalAlignment="Top" Click="buttonManageProducts_Click" HorizontalAlignment="Right" Width="105" />
        <Button Content="Manage Stores" Height="23" HorizontalAlignment="Right" Margin="0,40,173,0" Name="buttonManageLocations" VerticalAlignment="Top" Width="105" Click="buttonManageLocations_Click" />
        <Button Content="Manage Personal Locations" Height="23" HorizontalAlignment="Right" Margin="0,40,12,0" Name="buttonManagePersonalLocations" VerticalAlignment="Top" Width="155" Click="buttonManagePersonalLocations_Click" />
        <Button Content="Settings" Height="23" Margin="0,72,12,0" Name="buttonSettings" VerticalAlignment="Top" HorizontalAlignment="Right" Width="75" Click="buttonSettings_Click" />
        <!--<toolkit:BusyIndicator Margin="0,0,0,0" Name="busyIndicator1" IsBusy="{Binding IsBusy}"/>-->
    </Grid>
</UserControl>
